package com.wgl.controller;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.Timestamp;
import java.text.ParseException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.http.client.ClientProtocolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wgl.db.pojo.Train;
import com.wgl.service.TrainService;
import com.wgl.utl.RemainTicketThread;
import com.wgl.utl.Tool;

@Controller
@RequestMapping("ticket")
public class TicketController {
	@Resource
	private TrainService trainService;

	@RequestMapping("home")
	public String index(HttpServletRequest request, Model model) {
		return "index";
	}

	@RequestMapping(value = "getTrainList", produces = "application/json; charset=utf-8")
	@ResponseBody
	public String getTrainList(HttpServletRequest request, Model model)
			throws ClientProtocolException, URISyntaxException, IOException, ParseException {
		String fromStation = (String) request.getParameter("fromStation");
		String toStation = (String) request.getParameter("toStation");
		String trainDate = (String) request.getParameter("trainDate");
		String passengerType = (String) request.getParameter("passengerType");
		return trainService.getTrainList(fromStation, toStation, trainDate, passengerType);
	}

	@RequestMapping(value = "addTask", produces = "application/json; charset=utf-8")
	@ResponseBody
	public String addRemindTask(HttpServletRequest request, Model model) {
		String trainCode = (String) request.getParameter("trainCode");
		String trainDate = (String) request.getParameter("trainDate");
		String phoneNum = (String) request.getParameter("phoneNum");
		return trainService.addRemindTask(trainDate, trainCode, phoneNum);
	}

}
